import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/services.dart';
import 'package:yp/Xwidgets/button_widget.dart';
import 'package:yp/Xwidgets/cache_image.dart';
import 'package:yp/Xwidgets/line.dart';
import 'package:yp/config/config.dart';
import 'package:yp/config/style.dart';
import 'package:yp/helper.dart';
import 'package:yp/services/api.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yp/router.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/pages/order_list/logic.dart';

import '../state.dart';

class ItemWidget1 extends StatefulWidget {
  final Map<String, dynamic> data;
  final OrderListLogic logic;

  ItemWidget1({Key key, this.data, this.logic}) : super(key: key);

  @override
  _ItemWidgetState createState() => new _ItemWidgetState();
}

class _ItemWidgetState extends State<ItemWidget1> {
  Timer timer;
  int seconds;


  var timerValue = "";

  _timerTools(){

    int seconds = widget.data['residue_time'] ~/ (1000);
    // int seconds =111111 ~/ (1000);
    timer = Timer.periodic(Duration(seconds: 1), (timer) {
      setState(() {
        var d = Duration(seconds: seconds);
        List<String> parts = d.toString().split(':');
        timerValue = '${parts[0]}:${parts[1]}:${parts[2].split('.')[0]}';
        if (seconds == 0) {
          timer.cancel();
          return;
        }
        seconds = --seconds;
      });

    });
  }

  // @override
  void initState() {
    super.initState();
    if ((widget.data['residue_time'] != null) &&
        (widget.data['residue_time'] > 0)) {
      int seconds1 = widget.data['residue_time'] ~/ (1000);
      var d1 = Duration(seconds: seconds1);
      List<String> parts1 = d1.toString().split(':');
      timerValue = '${parts1[0]}:${parts1[1]}:${parts1[2].split('.')[0]}';
      WidgetsBinding.instance.addPostFrameCallback((_) => timeRun(context)); //
    }
    //界面build完成后执行回调函数
  }

  void timeRun(context) {
    if (widget.data['residue_time'] == null) {
      timerValue == '';
      return;
    }
    seconds = widget.data['residue_time'] ~/ (1000);
    timer = Timer.periodic(Duration(seconds: 1), (timer) {
      var d = Duration(seconds: seconds);
      List<String> parts = d.toString().split(':');
      timerValue = '${parts[0]}:${parts[1]}:${parts[2].split('.')[0]}';
      if (seconds == 0) {
        return;
      }
      setState(() {});
      seconds = --seconds;
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    timer?.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        GetBuilder<OrderListLogic>(builder: (logic) {
          return Container(
              width: 750.w,
              child: Padding(
                padding: EdgeInsets.symmetric(horizontal: 30.w),
                child: Column(
                  children: [
                    GestureDetector(
                      onTap: () {
                        if (logic.state.tabController.index != 5) {
                          Get.toNamed(RouteConfig.orderDetial, arguments: {
                            "id": widget.data['tml_num_id'],
                            "ordertype": 1,
                            'status': logic.state.tabController.index,
            'info:': null,

                          }).then((value){
                            print('========123afdfafafasfd========>');
                            logic.onReady();
                            logic.update();
                          });
                        } else {
                          Get.toNamed(RouteConfig.applyDetail, arguments: {
                            "id": widget.data['tml_num_id'],
                            "ordertype": 1,
                            'status': logic.state.tabController.index,
                          }).then((value){
                            print('========123afdfafafasfd========>');
                            logic.onReady();
                            logic.update();
                          });
                        }
                      },
                      child: Container(
                          padding: EdgeInsets.symmetric(
                            vertical: 32.w,
                          ),
                          decoration: BoxDecoration(
                            color: Colors.white,
                            border: Border(
                              bottom: BorderSide(
                                color: Color(0xfff0f0f0),
                              ),
                            ),
                          ),
                          child: Column(
                            children: [
                              Container(

                                child: Column(
                                  children: [
                                    Padding(
                                      padding: const EdgeInsets.only(bottom: 5),
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text(
                                              "买家：${widget.data['user_name']}",
                                              style: TextStyle(color: Color(0xff262626),fontSize: 24.sp)),
                                          Text(
                                            "${widget.data['operate_status_name']}",
                                            style: TextStyle(
                                                color: Config.mainColor,
                                                fontSize: 24.sp),
                                          ),

                                        ],
                                      ),
                                    ),
                                    Divider(height: 2.0,indent: 0,color: Colors.grey),
                                    Padding(
                                      padding: const EdgeInsets.only(top: 10),
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text("订单号：${widget.data['tml_num_id']}",style: TextStyle(color: Color(0xff999999),fontSize: 28.sp)),
                                          GestureDetector(
                                            onTap: () {
                                              ClipboardData data = new ClipboardData(text: widget.data['tml_num_id']);
                                              Clipboard.setData(data);
                                              toast("复制成功");
                                            },
                                            child: Container(
                                              width: 90.w,
                                              height: 40.w,
                                              margin: EdgeInsets.only(left: 20),
                                              decoration: BoxDecoration(
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(100)),
                                                border: Border.all(
                                                  color: Color(0xffe1e1e1),
                                                ),
                                              ),
                                              child: Center(
                                                child: Text("复制",style: TextStyle(fontSize: 24.sp, color: Color(0xff666666)),
                                                ),
                                              ),
                                            ),
                                          )


                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [

                                  Column(
                                    crossAxisAlignment:CrossAxisAlignment.start,
                                    children: [
                                      // Row(
                                      //   mainAxisAlignment:MainAxisAlignment.spaceBetween,
                                      //   children: [
                                      //     Text(
                                      //       "买家：${widget.data['user_name']}",
                                      //       style: TextStyle(color: Color(0xff262626),fontSize: 24.sp)),
                                      //     Text(
                                      //       "${widget.data['operate_status_name']}",
                                      //       style: TextStyle(
                                      //           color: Config.mainColor,
                                      //           fontSize: 28.sp),
                                      //     ),
                                      //     SizedBox(width: 100.w),
                                      //   ],
                                      // ),
                                      Padding(
                                        padding: EdgeInsets.symmetric(
                                            vertical: 10.w),
                                        child: Row(
                                          children: [
                                            // Text("订单号：${widget.data['tml_num_id']}",style: TextStyle(color: Color(0xff999999),fontSize: 28.sp)),
                                            // GestureDetector(
                                            //   onTap: () {
                                            //     ClipboardData data = new ClipboardData(text: widget.data['tml_num_id']);
                                            //     Clipboard.setData(data);
                                            //     toast("复制成功");
                                            //   },
                                            //   child: Container(
                                            //     width: 90.w,
                                            //     height: 40.w,
                                            //     margin: EdgeInsets.only(left: 10),
                                            //     decoration: BoxDecoration(
                                            //       borderRadius: BorderRadius.all(
                                            //           Radius.circular(100)),
                                            //       border: Border.all(
                                            //         color: Color(0xffe1e1e1),
                                            //       ),
                                            //     ),
                                            //     child: Center(
                                            //       child: Text("复制",style: TextStyle(fontSize: 24.sp, color: Color(0xff666666)),
                                            //       ),
                                            //     ),
                                            //   ),
                                            // )

                                          ],
                                        ),
                                        // child:
                                      ),
                                    ],
                                  ),

                                ],
                              ),

                              Column(
                                children: [
                                  ListView.separated(
                                    itemBuilder: (ctx, index) {
                                      var item =
                                          widget.data['distribution_order_item']
                                              [index];
                                      return Row(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        children: [
                                          Container(
                                            width: 128.w,
                                            height: 100.w,
                                            margin:
                                                EdgeInsets.only(right: 16.w),
                                            child: CachedImage(path:item['item_picture'],
                                              width:128.w ,
                                              height:100.w ,

                                            ),
                                          ),
                                          Container(
                                            height: 150.w,
                                            padding: EdgeInsets.symmetric(
                                                vertical: 10.w),
                                            child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              mainAxisAlignment:
                                                  MainAxisAlignment
                                                      .spaceBetween,
                                              children: [
                                                Container(
                                                  width: 510.w,
                                                  child: Text(
                                                    "${item['item_name']}",
                                                    style: TextStyle(
                                                      color: Color(0xff333333),
                                                      fontSize: 26.w,
                                                    ),
                                                    maxLines: 2,
                                                    textAlign: TextAlign.start,
                                                    overflow:
                                                        TextOverflow.ellipsis,
                                                  ),
                                                ),
                                                // Text(
                                                //   "${item['spec_nature_info'] ?? "" } "  ,
                                                //   style: TextStyle(
                                                //     color: Color(0xff888888),
                                                //     fontSize: 24.w,
                                                //   ),
                                                // ),
                                                RichText(
                                                  text: TextSpan(
                                                    children: [
                                                      TextSpan(
                                                        text: '￥',
                                                        style: TextStyle(
                                                            color: Colors.red,
                                                            fontSize: 32.w),
                                                      ),
                                                      TextSpan(
                                                        text:'${item['trade_price']}',
                                                        style: TextStyle(color: Colors.red, fontSize: 32.w)
                                                      ),
                                                      WidgetSpan(child: SizedBox(width: 10.w)),
                                                      TextSpan(
                                                        text:'x${num.parse(item['qty'].toString()).abs().toInt()}',
                                                        style: TextStyle(
                                                            color: Colors.red,
                                                            fontSize: 24.w),
                                                      ),
                                                    ],
                                                  ),
                                                ),

                                              ],
                                            ),

                                          ),

                                        ],
                                      );
                                    },
                                    shrinkWrap: true,
                                    physics: NeverScrollableScrollPhysics(),
                                    itemCount: widget
                                        .data['distribution_order_item'].length,
                                    separatorBuilder:
                                        (BuildContext context, int index) {
                                      return SizedBox(height: 10.w);
                                    },
                                  ),

                                ],
                              ),
                              // SizedBox(height:10.w),
                              Divider(
                                height: 1.0,
                                indent: 0,
                                color: Colors.grey,
                              ),
                              Container(
                                child: Column(
                                  children: [
                                    Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        Text('共${logic.fmtDouble2Int(widget.data['total_item_count'])}件'),
                                        Padding(
                                          padding:
                                              const EdgeInsets.only(top: 10),
                                          child: Row(
                                            children: [
                                              Text(widget.data['order_status'] == 1 ? '应付':'实付'),
                                              Text('¥'),
                                              Padding(
                                                padding: const EdgeInsets.only(left: 5),
                                                child: Text(
                                                    widget.data['order_status'] == 1 ? widget.data['need_pay_amount'].toString() :widget.data['real_pay_amount'].toString(),
                                                    style: TextStyle(color: Colors.red)),
                                              ),
                                            ],
                                          ),
                                        )
                                      ],
                                    ),
                                    Padding(
                                      padding: const EdgeInsets.only(top:10),
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.end,
                                        children: [
                                          // //Text(widget.data['order_status'].toString()),
                                          // Text(widget.data['order_status'] == 10 ? '返还:' : '可赚:'),
                                          // Text('¥'),
                                          // Padding(
                                          //   padding: const EdgeInsets.only(left: 5),
                                          //   child: Text(widget.data['commission_amount'].toString(),style: TextStyle(color: Colors.red)),
                                          // ),
                                        ],
                                      ),
                                    ),
                                    Padding(
                                      padding: const EdgeInsets.only(top: 20),
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.end,
                                        children: [
                                          Visibility(
                                            visible: widget.data['order_status'] == 1 ? true: false,
                                            child: GestureDetector(
                                              onTap:(){
                                                print('==========>${widget.data['total_amount']}');

                                                logic.state.total['all_payment'] = widget.data['total_amount'];
                                                // logic.update();
                                                // logic.optOrder(widget.data, '0');
                                                // 弹窗-去付款
                                                // 如果订单中有购物卡，则直接调用微信支付
                                                // 如果没有购物卡，则弹窗选择购物卡
                                                if(widget.data['card_type'] == 1 || logic.state.GiftcardList.length == 0){
                                                  //直接调起微信支付
                                                  logic.goToMoney(widget.data['tml_num_id'], widget.data['total_amount']);
                                                  return;
                                                }
                                                //如果是 0， 需要查询福利卡，减去福利卡金额  （total_amount）- 福利卡金额
                                                if(widget.data['card_type'] == 0 ){

                                                  setState(() {
                                                    logic.state.GiftcardList.forEach((element) {
                                                      element['click'] =false;
                                                    });
                                                    logic.state.isGiftNum = 0;
                                                  });
                                                  logic.state.isGiftMoney =widget.data['need_pay_amount'];
                                                  logic.state.realMoney =  widget.data['need_pay_amount'];
                                                  // 福利卡可多选
                                                  // 如果
                                                  showModalBottomSheet(
                                                      context: context,
                                                      // isDismissible: true,
                                                      isScrollControlled: true,
                                                      shape: RoundedRectangleBorder(
                                                          borderRadius: BorderRadius.only(
                                                              topLeft: Radius.circular(15),
                                                              topRight: Radius.circular(15))),
                                                      builder: (BuildContext context) {
                                                        return StatefulBuilder(
                                                            builder: (context1, state1) {
                                                              return AnimatedPadding(
                                                                //showModalBottomSheet 键盘弹出时自适应
                                                                  padding: MediaQuery.of(context)
                                                                      .viewInsets,
                                                                  duration: const Duration(
                                                                      milliseconds: 100),
                                                                  child: Container(
                                                                      constraints: BoxConstraints(
                                                                        minHeight: 90,
                                                                        maxHeight:
                                                                        MediaQuery.of(context)
                                                                            .size
                                                                            .height /
                                                                            1.2,
                                                                      ),
                                                                      child: Visibility(
                                                                        visible: widget.data['card_type'] == 1?false:true,
                                                                        child: ListView(
                                                                            shrinkWrap: true,
                                                                            children: [
                                                                              Container(
                                                                                  alignment: Alignment
                                                                                      .bottomCenter,
                                                                                  padding: EdgeInsets
                                                                                      .only(
                                                                                      top: 12),
                                                                                  child: Row(
                                                                                    children: [
                                                                                      SizedBox(
                                                                                          width:
                                                                                          36),
                                                                                      Expanded(
                                                                                        child: Text(
                                                                                            '选择支付方式',
                                                                                            style: TextStyle(
                                                                                                fontSize: 32
                                                                                                    .sp,
                                                                                                color: Color(
                                                                                                    0xff666666),
                                                                                                fontWeight: FontWeight
                                                                                                    .normal),
                                                                                            textAlign:
                                                                                            TextAlign.center),
                                                                                      ),
                                                                                      EsIconButton(
                                                                                        Icon(
                                                                                          Icons
                                                                                              .close,
                                                                                          size: 24,
                                                                                          color: Color(
                                                                                              0xffcccccc),
                                                                                        ),
                                                                                        padding: EdgeInsets.only(
                                                                                            right:
                                                                                            12),
                                                                                        onTap: () {
                                                                                          Navigator.of(
                                                                                              context)
                                                                                              .pop();
                                                                                        },
                                                                                      )
                                                                                    ],
                                                                                  )),
                                                                              Padding(
                                                                                padding:
                                                                                const EdgeInsets
                                                                                    .symmetric(
                                                                                    horizontal:
                                                                                    12,
                                                                                    vertical:
                                                                                    20),
                                                                                child: Row(
                                                                                  children: [
                                                                                    Image.asset(
                                                                                        'assets/images/selectIcon1.png',
                                                                                        width: 16,
                                                                                        height: 16),
                                                                                    SizedBox(
                                                                                      width: 8,
                                                                                    ),
                                                                                    Text(
                                                                                      '福利卡（已选${logic.state.isGiftNum.toInt()}张，共${logic.state.GiftcardList.length??0}张）',
                                                                                      style: TextStyle(
                                                                                          color: Color(
                                                                                              0xff333333),
                                                                                          fontSize:
                                                                                          32.sp,
                                                                                          fontWeight:
                                                                                          FontWeight
                                                                                              .normal),
                                                                                    ),
                                                                                    // Expanded(
                                                                                    //     child: Text(
                                                                                    //   '￥100.00',
                                                                                    //   maxLines: 1,
                                                                                    //   overflow:
                                                                                    //       TextOverflow
                                                                                    //           .ellipsis,
                                                                                    //   textAlign:
                                                                                    //       TextAlign
                                                                                    //           .end,
                                                                                    //   style: TextStyle(
                                                                                    //       color: EsColors
                                                                                    //           .TitleSecondary,
                                                                                    //       fontSize:
                                                                                    //           EsSizes
                                                                                    //               .MD,
                                                                                    //       fontWeight:
                                                                                    //           EsFontWeights
                                                                                    //               .Medium),
                                                                                    // ))
                                                                                  ],
                                                                                ),
                                                                              ),
                                                                              Container(
                                                                                margin:
                                                                                EdgeInsets.only(
                                                                                    left: 36,
                                                                                    bottom: 18),
                                                                                height: 155,
                                                                                child: ListView
                                                                                    .builder(
                                                                                    itemCount:logic.state.GiftcardList.length,
                                                                                    scrollDirection:Axis.horizontal,
                                                                                    shrinkWrap:true,
                                                                                    itemBuilder:(context, index) {
                                                                                      return GestureDetector(
                                                                                        onTap:() {
                                                                                          state1(() {
                                                                                            logic.setGift(index);// 修改点击状态
                                                                                          });

                                                                                          print('选择礼品卡');
                                                                                        },
                                                                                        child: Stack(
                                                                                            children: [
                                                                                              Container(
                                                                                                width: 190,
                                                                                                padding: EdgeInsets.all(6),
                                                                                                margin: EdgeInsets.only(right: 10),
                                                                                                child: Column(
                                                                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                                                                  mainAxisAlignment: MainAxisAlignment.start,
                                                                                                  children: [
                                                                                                    Image.asset('assets/images/welfare_card_cover.jpeg', width: 176, height: 100),
                                                                                                    // CachedImage(
                                                                                                    //     width: 176,
                                                                                                    //     height: 100,
                                                                                                    //     padding: EdgeInsets.zero,
                                                                                                    //     scale: BoxFit.fitWidth,
                                                                                                    //     path:
                                                                                                    //         'assets/images/welfare_card_cover'),
                                                                                                    Expanded(child: SizedBox(height: 2)),
                                                                                                    Text('中秋节福利卡',style: TextStyle(color: EsColors.TitleSecondary, fontSize: EsSizes.XS, fontWeight: EsFontWeights.Normal),),
                                                                                                    Row(
                                                                                                      children: [
                                                                                                        Expanded(
                                                                                                          child: Text(
                                                                                                            '￥${logic.state.GiftcardList[index]['money_available']}',
                                                                                                            maxLines: 1,
                                                                                                            overflow: TextOverflow.ellipsis,
                                                                                                            style: TextStyle(color: EsColors.TitleSecondary, fontSize: EsSizes.XS, fontWeight: EsFontWeights.Medium),
                                                                                                          ),
                                                                                                        ),
                                                                                                        // Text(
                                                                                                        //   '有效期至:${ state.GiftcardList[index]['expire_dtme'].toString()}',
                                                                                                        //   style: TextStyle(
                                                                                                        //       color: EsColors.Fill,
                                                                                                        //       fontSize: EsSizes.XXS,
                                                                                                        //       fontWeight:
                                                                                                        //           EsFontWeights.Normal),
                                                                                                        // )
                                                                                                      ],
                                                                                                    )
                                                                                                  ],
                                                                                                ),
                                                                                                decoration: BoxDecoration(
                                                                                                    color: EsColors.White,
                                                                                                    border: Border.all(
                                                                                                      color: EsColors.Primary,
                                                                                                      width: 1,
                                                                                                    ),
                                                                                                    borderRadius: BorderRadius.circular(3)),
                                                                                              ),
                                                                                              if(logic.state.GiftcardList[index]['click'])
                                                                                                Positioned(left: 0, top: 0, child: Image.asset('assets/images/selected_left.png', width: 47, height: 47))
                                                                                            ]),
                                                                                      );
                                                                                    }),
                                                                              ),
                                                                              YpLine(),
                                                                              GestureDetector(
                                                                                behavior:
                                                                                HitTestBehavior
                                                                                    .opaque,
                                                                                onTap: () {
                                                                                  state1(() {
                                                                                    // index = 0;
                                                                                    print(
                                                                                        '切换支付方式微信');
                                                                                  });
                                                                                },
                                                                                child: Padding(
                                                                                  padding: const EdgeInsets
                                                                                      .symmetric(
                                                                                      horizontal:
                                                                                      12,
                                                                                      vertical: 20),
                                                                                  child: Row(
                                                                                    children: [
                                                                                      Image.asset(
                                                                                          'assets/images/selectIcon1.png',
                                                                                          width: 16,
                                                                                          height:
                                                                                          16),
                                                                                      SizedBox(
                                                                                        width: 8,
                                                                                      ),
                                                                                      Text(
                                                                                        '微信支付',
                                                                                        style: TextStyle(
                                                                                            color: EsColors
                                                                                                .TitleSecondary,
                                                                                            fontSize:
                                                                                            EsSizes
                                                                                                .MD,
                                                                                            fontWeight:
                                                                                            EsFontWeights.Normal),
                                                                                      ),
                                                                                      Expanded(
                                                                                          child:
                                                                                          Text(
                                                                                            '￥${logic.state.isGiftMoney}',
                                                                                            maxLines: 1,
                                                                                            overflow:
                                                                                            TextOverflow
                                                                                                .ellipsis,
                                                                                            textAlign:
                                                                                            TextAlign
                                                                                                .end,
                                                                                            style: TextStyle(
                                                                                                color: EsColors
                                                                                                    .TitleSecondary,
                                                                                                fontSize:
                                                                                                EsSizes
                                                                                                    .MD,
                                                                                                fontWeight:
                                                                                                EsFontWeights.Medium),
                                                                                          ))
                                                                                    ],
                                                                                  ),
                                                                                ),
                                                                              ),
                                                                              YpLine(),
                                                                              GestureDetector(
                                                                                behavior:
                                                                                HitTestBehavior
                                                                                    .opaque,
                                                                                onTap: () {
                                                                                  state1(() {
                                                                                    // index = 1;
                                                                                    print(
                                                                                        '切换支付方式支付宝');
                                                                                  });
                                                                                },
                                                                                child: Padding(
                                                                                  padding: const EdgeInsets
                                                                                      .symmetric(
                                                                                      horizontal:
                                                                                      12,
                                                                                      vertical: 20),
                                                                                ),
                                                                              ),
                                                                              YpLine(),
                                                                              SizedBox(height: 27),
                                                                              // Center(
                                                                              //   child: RichText(
                                                                              //     text: TextSpan(
                                                                              //       children: [
                                                                              //         TextSpan(
                                                                              //           text: '应付：',
                                                                              //           style: TextStyle(
                                                                              //               color: EsColors.Primary,
                                                                              //               fontSize: EsSizes.XS,
                                                                              //               fontWeight: EsFontWeights.Normal),
                                                                              //         ),
                                                                              //         TextSpan(
                                                                              //           text: '￥422.08',
                                                                              //           style: TextStyle(
                                                                              //               color: EsColors.Primary,
                                                                              //               fontSize: EsSizes.LG,
                                                                              //               fontWeight: EsFontWeights.Medium),
                                                                              //         )
                                                                              //       ],
                                                                              //     ),
                                                                              //   ),
                                                                              // ),
                                                                              SizedBox(height: 16),
                                                                              EsBottomWidget(
                                                                                  leftTitle: null,
                                                                                  rightTitle:'确认付款',
                                                                                  rightlick: () {
                                                                                    //gyq
                                                                                    print('确认付款');
                                                                                    var amt = logic.calculateCardAmount();
                                                                                    print(amt);
                                                                                    if(widget.data['total_amount'] == amt){// 1. 卡金额等于订单金额
                                                                                      var realAmt = 0.0;
                                                                                      //logic.goToMoney(widget.data['tml_num_id'], realAmt);
                                                                                      Navigator.of(context).pop();
                                                                                    }else if(amt < widget.data['total_amount']){// 2. 卡金额小于订单金额
                                                                                      var realAmt = widget.data['total_amount'] - amt;
                                                                                      logic.goToMoney(widget.data['tml_num_id'], realAmt);
                                                                                      Navigator.of(context).pop();
                                                                                      //logic.toPay(realAmt);
                                                                                    }else{
                                                                                      // 如果卡金额大于订单金额，直接去支付
                                                                                      var realAmt = widget.data['total_amount'];
                                                                                      logic.goToMoney(widget.data['tml_num_id'], realAmt);
                                                                                      Navigator.of(context).pop();
                                                                                    }
                                                                                  },
                                                                                  decoration: null)
                                                                            ]),
                                                                      )));
                                                            });
                                                      });
                                                }
                                              },
                                              child: Container(
                                                decoration: new BoxDecoration(
                                                    border: new Border.all(
                                                        color: Color(0xFFFF0000),
                                                        width: 0.3),

                                                    borderRadius:
                                                        new BorderRadius.circular(
                                                            (20.0))),
                                                child: Row(
                                                  children: [
                                                    Text('继续付款',style: TextStyle(color: Color(0xFFFF0000),fontSize: 10)),
                                                    // Text(widget.data['timerValue']??'0:00:00')
                                                    Padding(
                                                      padding: const EdgeInsets.only(left: 10),
                                                      child: Text(timerValue,style: TextStyle(color: Color(0xFFFF0000),fontSize: 10)),
                                                    ),
                                                  ],
                                                ),
                                                // child: Text('继续付款',style: TextStyle(color: Colors.grey,fontSize: 10)),
                                                padding: EdgeInsets.only(top: 4,bottom: 4,left: 8,right: 8),
                                                margin: EdgeInsets.only(right: 15),
                                              ),
                                            ),
                                          ),
                                          Visibility(
                                            visible: widget.data['order_status'] == 1 ? true: false,
                                            child: GestureDetector(
                                              onTap:(){
                                                logic.optOrder(widget.data, '1');
                                              },
                                              child: Container(
                                                decoration: new BoxDecoration(
                                                    border: new Border.all(
                                                        color: Color(0xFFFF0000),
                                                        width: 0.3),
                                                    borderRadius:
                                                    new BorderRadius.circular(
                                                        (20.0))),
                                                child: Text('取消订单',style: TextStyle(color: Color(0xFFFF0000),fontSize: 10)),
                                                padding: EdgeInsets.only(top: 4,bottom: 4,left: 8,right: 8),
                                              ),
                                            ),
                                          ),
                                          Visibility(
                                            visible: (widget.data['order_status'] != 1 && widget.data['order_status'] != 9) && widget.data['type_num_id'] == 1? true: false,
                                            child: GestureDetector(
                                              onTap:(){
                                                // print('=======================>');
                                                // print(widget.data['card_type']);
                                                // print(widget.data['order_status']);
                                                Get.toNamed(RouteConfig.logistics,
                                                    parameters: {
                                                      'tmlId': widget.data["tml_num_id"],
                                                      'transCode':widget.data["ship_tran_no_by_tml_num_ids"]
                                                    });
                                                // Get.toNamed(RouteConfig.issueInvoice, arguments: widget.data);
                                              },
                                              child: Container(
                                                decoration: new BoxDecoration(
                                                    border: new Border.all(
                                                        color: Color(0xFFFF0000),
                                                        width: 0.3),
                                                    borderRadius:
                                                    new BorderRadius.circular(
                                                        (20.0))),
                                                child: Text('查看物流',style: TextStyle(color: Color(0xFFFF0000),fontSize: 10)),
                                                padding: EdgeInsets.only(top: 4,bottom: 4,left: 8,right: 8),
                                                margin: EdgeInsets.only(right: 15),
                                              ),
                                            ),
                                          ),
                                          Visibility(
                                            visible: widget.data['order_status'] == 17|| widget.data['order_status'] == 10? true: false,
                                            child: GestureDetector(
                                              onTap:(){
                                                logic.optOrder(widget.data, '2');
                                              },
                                              child: Container(
                                                decoration: new BoxDecoration(
                                                    border: new Border.all(
                                                        color: Color(0xFFFF0000),
                                                        width: 0.3),
                                                    borderRadius:
                                                    new BorderRadius.circular(
                                                        (20.0))),
                                                child: Text('撤销申请',style: TextStyle(color: Color(0xFFFF0000),fontSize: 10)),
                                                padding: EdgeInsets.only(top: 4,bottom: 4,left: 8,right: 8),
                                                margin: EdgeInsets.only(right: 15),
                                              ),
                                            ),
                                          ),
                                          Visibility(
                                            visible: widget.data['comment_type'] == 0 && widget.logic.state.index !=5? true: false,
                                            child: GestureDetector(
                                              onTap:(){
                                                //评价晒单 跳转
                                                // print('  评价参数   widget.data = ${widget.data} ');
                                                var params = {
                                                  'use_platform': 2,
                                                  'access_token': SpUtil.getString('token'),
                                                  'usr_num_id': SpUtil.getInt('empeNumId'),
                                                };
                                                EasyLoading.show();
                                                Api.viewEvaluationPermission(params).listen((event) {
                                                  EasyLoading.dismiss();
                                                  if (event['code'] == 0) {
                                                    String blackType = event['black_type'].toString();
                                                    if (!blackType.contains('2')) {
                                                      Get.toNamed(
                                                        RouteConfig.pingJiaShaiDan,
                                                        arguments: widget.data,
                                                        parameters: {
                                                          'id': widget.data["tml_num_id"],
                                                        },
                                                      );
                                                      return ;
                                                    }
                                                  }
                                                  toast('评价权限暂时关闭，请联系客服');
                                                }, onError: (error) {
                                                  EasyLoading.dismiss();
                                                });
                                              },
                                              child: Container(
                                                decoration: new BoxDecoration(
                                                    border: new Border.all(
                                                        color: Color(0xFFFF0000),
                                                        width: 0.3),
                                                    borderRadius:
                                                    new BorderRadius.circular(
                                                        (20.0))),
                                                child: Text('评价晒单',style: TextStyle(color: Color(0xFFFF0000),fontSize: 10)),
                                                padding: EdgeInsets.only(top: 4,bottom: 4,left: 8,right: 8),
                                                margin: EdgeInsets.only(right: 15),
                                              ),
                                            ),
                                          ),
                                          Visibility(
                                            visible: (widget.data['order_status'] == 27|| widget.data['order_status'] == 28 || widget.data['operate_status_num_id'] == 90103) && widget.data['tran_type_num_id'] == 3 && widget.data['remain_back_qty'] > 0 ? true: false,
                                            child: GestureDetector(
                                              onTap:(){
                                                logic.optOrder(widget.data, '3');
                                              },
                                              child: Container(
                                                decoration: new BoxDecoration(
                                                    border: new Border.all(
                                                        color: Color(0xFFFF0000),
                                                        width: 0.3),
                                                    borderRadius:
                                                    new BorderRadius.circular(
                                                        (20.0))),
                                                child: Text('确认收货',style: TextStyle(color: Color(0xFFFF0000),fontSize: 10)),
                                                padding: EdgeInsets.only(top: 4,bottom: 4,left: 8,right: 8),
                                                margin: EdgeInsets.only(right: 15),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    )
                                  ],
                                ),
                              )
                              // Row(
                              //   crossAxisAlignment: CrossAxisAlignment.end,
                              //   mainAxisAlignment: MainAxisAlignment.end,
                              //   children: [
                              //     Text(
                              //       "订单总价：￥${widget.data['total_amount']}",
                              //       style: TextStyle(
                              //         fontSize: 28.sp,
                              //         color: Color(0xff666666),
                              //       ),
                              //     ),
                              //   ],
                              // ),
                              // SizedBox(height:10.w),
                              // widget.data['operate_status_name']!='交易失败' ?
                              // Row(
                              //   crossAxisAlignment: CrossAxisAlignment.end,
                              //   mainAxisAlignment: MainAxisAlignment.end,
                              //   children: [
                              //     RichText(
                              //       text: TextSpan(
                              //         children: [
                              //           TextSpan(
                              //             text: '可赚：',
                              //             style: TextStyle(color: Color(0xff666666), fontSize: 32.w),
                              //           ),
                              //           WidgetSpan(child: SizedBox(width:10.w)),
                              //           TextSpan(
                              //             text: '￥${widget.data['commission_amount'] ?? 0.0 }',
                              //             style: TextStyle(color: Color(0xff222222), fontSize: 32.w),
                              //           ),
                              //         ],
                              //       ),
                              //     )
                              //   ],
                              // ):Container(),
                            ],
                          )),
                    ),
                    // logic.state.tabController.index <= 2 ||
                    //         widget.data['operate_status_name'] == '交易失败'
                    //     ? Container()
                    //     : Container(
                    //         height: 100.w,
                    //         color: Colors.white,
                    //         child: Row(
                    //           mainAxisAlignment: logic.state.index == 5
                    //               ? MainAxisAlignment.spaceBetween
                    //               : MainAxisAlignment.end,
                    //           children: [
                    //             if (logic.state.index == 5)
                    //               if (widget.data['return_way'] == 1)
                    //                 Text(
                    //                   "仅退款",
                    //                   style: TextStyle(
                    //                     fontSize: 28.w,
                    //                     color: Color(0xff222222),
                    //                   ),
                    //                 ),
                    //             if (widget.data['return_way'] == 2)
                    //               Text(
                    //                 "退货退款",
                    //                 style: TextStyle(
                    //                   fontSize: 28.w,
                    //                   color: Color(0xff222222),
                    //                 ),
                    //               ),
                    //             // if (logic.state.tabController.index != 5)
                    //             //   GestureDetector(
                    //             //     onTap: () {
                    //             //       Get.toNamed(RouteConfig.logistics,
                    //             //           parameters: {
                    //             //             'id': widget.data["tml_num_id"],
                    //             //           });
                    //             //     },
                    //             //     child: Container(
                    //             //       width: 160.w,
                    //             //       height: 60.w,
                    //             //       decoration: BoxDecoration(
                    //             //         borderRadius: BorderRadius.all(
                    //             //           Radius.circular(80),
                    //             //         ),
                    //             //         border: Border.all(
                    //             //           color: Color(0xffCCCCCC),
                    //             //         ),
                    //             //       ),
                    //             //       child: Center(
                    //             //         child: Text(
                    //             //           "物流信息",
                    //             //           style: TextStyle(
                    //             //             fontSize: 28.w,
                    //             //             color: Color(0xff222222),
                    //             //           ),
                    //             //         ),
                    //             //       ),
                    //             //     ),
                    //             //   ),
                    //             if (logic.state.tabController.index == 1)
                    //               GestureDetector(
                    //                 onTap: () {
                    //                   logic.goToMoney(widget.data['tml_num_id'],
                    //                       widget.data['total_amount']);
                    //                 },
                    //                 child: Container(
                    //                   height: 60.w,
                    //                   margin: EdgeInsets.only(left: 20.w),
                    //                   padding: EdgeInsets.symmetric(
                    //                       horizontal: 20.w),
                    //                   decoration: BoxDecoration(
                    //                     borderRadius: BorderRadius.all(
                    //                       Radius.circular(80),
                    //                     ),
                    //                     color: Config.mainColor,
                    //                   ),
                    //                   child: Center(
                    //                       child: Text(
                    //                     "去付款${timerValue}",
                    //                     style: TextStyle(
                    //                       fontSize: 28.w,
                    //                       color: Colors.white,
                    //                     ),
                    //                   )),
                    //                 ),
                    //               ),
                    //           ],
                    //         ),
                    //       ),
                  ],
                ),
              ));
        }),
        Container(
          height: 20.w,
          color: Color(0xffF7F7F7),
        )
      ],
    );
  }
}
